#include <cstdarg>
#include <ctime>
#include <chrono>
#include <iostream>
#include "logger.h"

#define LOGGER_PREFIX "[ocean-vagsdk-jni]"

void PrintLog(const char *fmt, ...) {
    // 获取当前系统时间并格式化
    auto currentTime = std::chrono::system_clock::now();
    std::time_t tt = std::chrono::system_clock::to_time_t(currentTime);
    char timeBuffer[32];
    std::strftime(timeBuffer, sizeof(timeBuffer), "%Y-%m-%d %H:%M:%S", std::localtime(&tt));

    // 创建完整的日志前缀
    std::string logPrefix = std::string(LOGGER_PREFIX) + " [" + timeBuffer + "] ";

    // 处理可变参数并格式化日志信息
    va_list args;
    va_start(args, fmt);
    std::string logMessage = logPrefix + fmt;
    vfprintf(stdout, logMessage.c_str(), args);
    va_end(args);

    // 确保日志即时输出到控制台
    fflush(stdout);
}
